package com.victor.controller.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.victor.entity.Bybookcoupon;
import com.victor.service.BybookcouponService;
import com.victor.utils.Msg;

/**
 * 购书卷管理
 * 
 * @author zhangbin
 *
 */
@RestController
@RequestMapping("/bybookcoupon")
public class BybookcouponController {

	@Autowired
	private BybookcouponService bybookcouponService;


	// 查询购书卷
	@RequestMapping("/getBybookcouponList")
	public Msg getBybookcouponList() {
		List<Bybookcoupon> bybookcoupons = bybookcouponService.getBybookcouponList();
		if (bybookcoupons != null && bybookcoupons.size() > 0) {
			return Msg.success().add("bybookcoupons", bybookcoupons);
		}
		return Msg.fail("未查询到购书卷");
	}

	// 添加购书卷
	@RequestMapping("/addBybookcoupon")
	public Msg addBybookcoupon(@RequestBody List<Bybookcoupon> bybookcoupons) {
		if (bybookcoupons == null || bybookcoupons.size() == 0) {
			return Msg.fail("参数错误");
		}
		for (Bybookcoupon bybookcoupon : bybookcoupons) {
			bybookcouponService.addBybookcoupon(bybookcoupon);
		}
		return Msg.success();
	}

	// 批量删除购书卷
	@RequestMapping("/batchDelete")
	public Msg batchDelete(int[] ids) {
		if (ids == null || ids.length == 0) {
			return Msg.fail("参数错误");
		}
		boolean delResult = bybookcouponService.batchDelete(ids);

		return Msg.judge(delResult);
	}

}
